package brc.syntacticTree;

import java.io.IOException;
import java.io.Writer;

public class BinaryBooleanExprNode extends BooleanExprNode {
	private static final long serialVersionUID = 6102528227007400692L;
	private BooleanExprNode left;
	private BooleanExprNode right;
	private LogicalOperation operation;
	
	public BinaryBooleanExprNode(BooleanExprNode left, BooleanExprNode right, LogicalOperation operation) {
		if (left == null || right == null || operation == null) {
			throw new NullPointerException("Left, right members and operation must be specified");
		}
		this.left = left;
		this.right = right;
		this.operation = operation;
	}
	
	public BooleanExprNode getLeft() {
		return left;
	}
	public BooleanExprNode getRight() {
		return right;
	}
	public LogicalOperation getOperation() {
		return operation;
	}

	@Override
	public void writeAssembly(Writer writer) throws IOException {
		this.left.writeAssembly(writer);
		this.right.writeAssembly(writer);
		
		switch (this.operation) {
		case And:
			writer.write("iand\r\n");
			break;
		case Or:
			writer.write("ior\r\n");
			break;
		}
	}

	@Override
	public void semanticCheck() throws SemanticException {
		this.left.semanticCheck();
		this.right.semanticCheck();
	}

	public enum LogicalOperation {
		And,
		Or
	}
}
